﻿using System;
using System.Collections;
using System.Configuration;
using System.ComponentModel;
using System.Data;
using System.Linq;

using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

using System.Text;

using LinkCard.Utils;
using LinkCard.Model;

namespace LinkCard.CustomerView
{
    public partial class RegisterResult : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString["option"].ToString() == "en")
            {
                string SECURE_SECRET = "6D0870CDE5F24F34F3915FB0045120DB";
                string hashvalidateResult = "";
                // Khoi tao lop thu vien
                VPCRequest conn = new VPCRequest("http://onepay.vn");
                conn.SetSecureSecret(SECURE_SECRET);
                // Xu ly tham so tra ve va kiem tra chuoi du lieu ma hoa
                hashvalidateResult = conn.Process3PartyResponse(Page.Request.QueryString);
                // Lay gia tri tham so tra ve tu cong thanh toan
                String vpc_TxnResponseCode = conn.GetResultField("vpc_TxnResponseCode", "Unknown");
                string amount = conn.GetResultField("vpc_Amount", "Unknown");
                string localed = conn.GetResultField("vpc_Locale", "Unknown");
                string command = conn.GetResultField("vpc_Command", "Unknown");
                string version = conn.GetResultField("vpc_Version", "Unknown");
                string cardType = conn.GetResultField("vpc_Card", "Unknown");
                string orderInfo = conn.GetResultField("vpc_OrderInfo", "Unknown");
                string merchantID = conn.GetResultField("vpc_Merchant", "Unknown");
                string authorizeID = conn.GetResultField("vpc_AuthorizeId", "Unknown");
                string merchTxnRef = conn.GetResultField("vpc_MerchTxnRef", "Unknown");
                string transactionNo = conn.GetResultField("vpc_TransactionNo", "Unknown");
                string acqResponseCode = conn.GetResultField("vpc_AcqResponseCode", "Unknown");
                string txnResponseCode = vpc_TxnResponseCode;
                string message = conn.GetResultField("vpc_Message", "Unknown");

                if (hashvalidateResult == "CORRECTED" && txnResponseCode.Trim() == "0")
                {
                    vpc_Result.Text = "Transaction was paid successful";
                }
                else if (hashvalidateResult == "INVALIDATED" && txnResponseCode.Trim() == "0")
                {
                    vpc_Result.Text = "Transaction is pending";
                }
                else
                {
                    vpc_Result.Text = "Transaction was not paid successful";
                }
            }
            else if (Request.QueryString["option"].ToString() == "vn")
            {
                string SECURE_SECRET = "A3EFDFABA8653DF2342E8DAC29B51AF0";
                string hashvalidateResult = "";
                // Khoi tao lop thu vien
                VPCRequest conn = new VPCRequest("http://onepay.vn");
                conn.SetSecureSecret(SECURE_SECRET);
                // Xu ly tham so tra ve va kiem tra chuoi du lieu ma hoa
                hashvalidateResult = conn.Process3PartyResponse(Page.Request.QueryString);

                // Lay gia tri tham so tra ve tu cong thanh toan
                String vpc_TxnResponseCode = conn.GetResultField("vpc_TxnResponseCode", "Unknown");
                string amount = conn.GetResultField("vpc_Amount", "Unknown");
                string localed = conn.GetResultField("vpc_Locale", "Unknown");
                string command = conn.GetResultField("vpc_Command", "Unknown");
                string version = conn.GetResultField("vpc_Version", "Unknown");
                string cardBin = conn.GetResultField("vpc_Card", "Unknown");
                string orderInfo = conn.GetResultField("vpc_OrderInfo", "Unknown");
                string merchantID = conn.GetResultField("vpc_Merchant", "Unknown");
                string authorizeID = conn.GetResultField("vpc_AuthorizeId", "Unknown");
                string merchTxnRef = conn.GetResultField("vpc_MerchTxnRef", "Unknown");
                string transactionNo = conn.GetResultField("vpc_TransactionNo", "Unknown");
                string txnResponseCode = vpc_TxnResponseCode;
                string message = conn.GetResultField("vpc_Message", "Unknown");

                if (hashvalidateResult == "CORRECTED" && txnResponseCode.Trim() == "0")
                {
                    vpc_Result.Text = "Transaction was paid successful";
                }
                else if (hashvalidateResult == "INVALIDATED" && txnResponseCode.Trim() == "0")
                {
                    vpc_Result.Text = "Transaction is pending";
                }
                else
                {
                    vpc_Result.Text = "Transaction was not paid successful";
                }
            }
        }
    }
}